package tq.com.tqteacher.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

import tq.com.tqcom.net.INetCallback;
import tq.com.tqteacher.net.TQNetInterface;
import tq.com.tqteacher.propertyEnum.TQModify;

public class TQTBNewPublish extends TQNewPublish {
    private String pdfFile;

    public String getPdfFile() {
        return pdfFile;
    }

    public void setPdfFile(String pPdfFile) {
        pdfFile = pPdfFile;
    }

    public void refreshAttach(JSONArray pObject){
        if(pObject == null || pObject.length() == 0) return;
        try {
            JSONObject lObject = pObject.getJSONObject(0);
            pdfFile = lObject.optString("filelist");
        }catch (JSONException pE){
            pE.printStackTrace();
        }
    }

    public void onPulishComplete(INetCallback pNetCallback){
        HashMap<String, Object> param = new HashMap<>();
        param.put("category", Integer.valueOf(getType()));
        param.put("title", getName());
        param.put("desc", getDesc());
        param.put("grade", Integer.valueOf(getGrade()));
        param.put("chapter", Integer.valueOf(getParentId()));
        param.put("access_type", Integer.valueOf(getShow()));

        TQNetInterface.newPublish(param, pNetCallback);
    }

    public void onModifyBaseInfo(INetCallback pNetCallback){
        HashMap<TQModify.MaterialBaseInfo, Object> param = new HashMap<>();
        param.put(TQModify.MaterialBaseInfo.title, getName());
        param.put(TQModify.MaterialBaseInfo.desc, getDesc());
        param.put(TQModify.MaterialBaseInfo.access_type, String.valueOf(getShow()));
        param.put(TQModify.MaterialBaseInfo.grade, String.valueOf(getGrade()));

        TQNetInterface.modifyMaterialInfo(getSeq_id(), param, pNetCallback);
    }
}
